//静态方法
const strats = {}
const LIFECYCLE = [
    'beforeCreate',
    'created'
]
LIFECYCLE.forEach(hook => {
    strats[hook] = function (p, c) {// 父亲，儿子
        if (c) {
            if (p) {
                return p.concat(c)
            } else {
                return [c]
            }
        } else {
            return p
        }
    }
})

export function mergeOptions(parent, child) {
    const options = {}
    for (const key in parent) {
        mergeField(key)
    }
    for (const key in child) {
        if (!parent.hasOwnProperty(key)) {
            mergeField(key)
        }

    }

    function mergeField(key) {
        //策略模式减少if
        if (strats[key]) {
            options[key] = strats[key](parent[key], child[key])
        } else {
            // 不在策略中以儿子为主
            options[key] = child[key] || parent[key]
        }

    }
    return options
}